import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/operational_statistics/operational_statistics_model.dart';
import 'package:ls_work/operational_statistics/response/month_into_out_data.dart';
import 'package:ls_work/util/ext_utils.dart';

import '../response/month_activity_data.dart';
class OperationalStatisticsViewModel extends BaseListViewModel<String>{


  OperationalStatisticsViewModel(super.context);

  var model = OperationalStatisticsModel();

  String yearMonthStart = "";

  String yearMonthEnd = "";

  var format = [yyyy,'-',mm,'-',dd];

  ///总床位数量
  num totalBedNum = 0;
  ///总入住数
  num totalIntoNum = 0;
  ///入住率
  dynamic intoPercent;

  num todayInto = 0;

  num todayOut = 0;

  num monthInto = 0;

  num monthOut = 0;

  num monthOrderNum = 0;

  num monthNurseTimes = 0;

  num monthWarningTimes = 0;

  MonthIntoOutData? monthInOutChart;

  MonthActivityData? monthActivityChart;

  void initMonthDate(){
    var now = DateTime.now();
    var thisMonth = DateTime(now.year,now.month,1);
    var halfYearMonth = DateTime(now.year,now.month-5,1);
    yearMonthStart = halfYearMonth.toDateStr(format);
    yearMonthEnd = thisMonth.toDateStr(format);
  }

  @override
  void onCreated() {
    super.onCreated();
    initMonthDate();
    requestRefresh();
  }


  @override
  Future<List<String>> requestListData() async {
    var bedInfo = await model.bedStatistics();
    totalBedNum = bedInfo.bedNumber??0;
    totalIntoNum = bedInfo.elders??0;
    intoPercent = ((bedInfo.bedUseRate??0).d)*(100.d);

    var todayInfo = await model.todayInto();
    todayInto = todayInfo.bedCheckin??0;
    todayOut = todayInfo.bedCheckout??0;

    var monthInfo = await model.monthInto();
    monthInto = monthInfo.intoCount??0;
    monthOut = monthInfo.checkOutCount??0;

    var serviceInfo = await model.monthServiceStatistics();
    monthOrderNum = serviceInfo['serveCount']??0;
    monthNurseTimes = serviceInfo['monthTakeCarePlanCount']??0;
    monthWarningTimes = serviceInfo['fallInfoCount']??0;

    monthInOutChart = await model.monthInOutChart(yearMonthStart, yearMonthEnd);
    monthActivityChart = await model.monthActivity(yearMonthStart, yearMonthEnd);


    return [""];
  }
}